package com.ea.admin.service.impl;

import com.ea.admin.mapper.PropertiesInfoMapper;
import com.ea.admin.pojo.po.PropertiesInfo;
import com.ea.admin.service.PropertiesService;
import com.ea.common.mybatis.UpdateBatchWrapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PropertiesServiceImpl implements PropertiesService {
    @Resource
    PropertiesInfoMapper propertiesInfoMapper;

    @Override
    public void updatePropertiesByCompanyConf(List<Long> companyConfId, List<String> propertiesName) {
        if (companyConfId == null || companyConfId.isEmpty()) {
            return;
        }
        List<PropertiesInfo> updateList = propertiesInfoMapper.selectListByPropertiesByCompanyConfId(companyConfId);
        for (int i = 0; i < updateList.size(); i++) {
            updateList.get(i).setPropertiesName(propertiesName.get(i));
        }
        propertiesInfoMapper.updateBatchById(updateList,
                new UpdateBatchWrapper<PropertiesInfo>().setUpdateFields(
                        PropertiesInfo::getPropertiesName
                ));
    }
}
